package org.ucas.faker.web.service.graph;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.ucas.faker.web.model.KeywordNode;
import org.ucas.faker.web.utils.model.TreeTerm;

import java.util.List;

@Service
@Transactional
public class TreeTermService {

    @Autowired private SpecialKeywordService specialKeywordService;

    public TreeTerm getTreeTerm(long treeId){
//        TreeTerm term = testTreeTerm();
        TreeTerm term = getTreeTermByDeoptId(treeId);
        return term;
    }

    public TreeTerm getTreeTermByDeoptId(long treeId){
//        TreeTerm term = new TreeTerm("磁随机存取存储器MRAM");
//        treeId = 1;
        List<KeywordNode> keywordList =  specialKeywordService.getSpecialKeywordTree(treeId);
        if (keywordList.size()<=0){
            return new TreeTerm("未知关键词","Unknown");
        }
        KeywordNode rootKeyword = keywordList.get(0);
        TreeTerm term = new TreeTerm(rootKeyword.getValue());
        //二层遍历
        for (KeywordNode subKeyword : rootKeyword.getChild()){
            TreeTerm subTerm = new TreeTerm(subKeyword.getValue());

            //三层遍历
            for (KeywordNode leafKeyword : subKeyword.getChild()){
                TreeTerm leafTerm = new TreeTerm(leafKeyword.getValue());
                subTerm.addChildTerm(leafTerm);
            }
            term.addChildTerm(subTerm);
        }

        return term;
    }

    public TreeTerm testTreeTerm(){
        TreeTerm term = new TreeTerm("磁随机存取存储器MRAM");

        TreeTerm subTerm1 = new TreeTerm("GMR/自旋阀型MRAM");
        TreeTerm subTerm2 = new TreeTerm("第一代基于MTJ存储单元的磁场驱动型MRAM");
        TreeTerm subTerm3 = new TreeTerm("第二代基于MTJ存储单元的电流驱动型STT-MRAM");
        TreeTerm subTerm4 = new TreeTerm("新一代基于MTJ存储单元的自旋轨道力矩型磁随机存储器(SOT-MRAM)");
        TreeTerm subTerm5 = new TreeTerm("基于MTJ的畴壁移动型MRAM");
        TreeTerm subTerm6 = new TreeTerm("磁性膜畴壁移动型赛道存储器");
        TreeTerm subTerm7 = new TreeTerm("基于斯格明子存储单元的MRAM/赛道存储器", "MRAM based on Skyrmion");
        TreeTerm subTerm8 = new TreeTerm("基于MTJ存储单元的电场驱动型MRAM");

        subTerm1.addChildTerm("合金", "Heusler alloy");
        subTerm1.addChildTerm("间隔层", "Spacer");
        subTerm1.addChildTerm("磁性层", "Magnetic layer");
        subTerm1.addChildTerm("Current perpendicular to plane", "CPP");
        subTerm1.addChildTerm("磁场驱动型", "Driven by Magnetic field");
        subTerm1.addChildTerm("STT驱动型", "Driven by STT");
        subTerm1.addChildTerm("热辅助", "Heat-assisted");
        subTerm1.addChildTerm("操作次数", "Endurance");

        subTerm2.addChildTerm("星型", "Astroid-MRAM");
        subTerm2.addChildTerm("嵌套型", "Toggle-MRAM");
        subTerm2.addChildTerm("单势垒", "single barrier layer");
        subTerm2.addChildTerm("双势垒", "double barrier layer");
        subTerm2.addChildTerm("三氧化二铝", "Al2O3");
        subTerm2.addChildTerm("氧化镁", "MgO");
        subTerm2.addChildTerm("尖晶石势垒", "spinel");
        subTerm2.addChildTerm("碳基势垒材料", "carbon based barrier material");
        subTerm2.addChildTerm("实心椭圆", "elliptical pillar");
        subTerm2.addChildTerm("纳米环", "nanoring");
        subTerm2.addChildTerm("热辅助", "heat-assistant");
        subTerm2.addChildTerm("磁性层", "magnetic layer");

        subTerm3.addChildTerm("面内磁化", "Magnetization in plane");
        subTerm3.addChildTerm("三氧化二铝势垒", "Al2O3-Barrier type");
        subTerm3.addChildTerm("多边形结区", "Polygon Geometry");
        subTerm3.addChildTerm("环状", "Ring type");
        subTerm3.addChildTerm("氧化镁势垒", "MgO-Barrier type");
        subTerm3.addChildTerm("铝酸镁势垒", "MgAl2O4-Barrier type");
        subTerm3.addChildTerm("低电流密度", "Low Current Density");
        subTerm3.addChildTerm("电场辅助", "Electric ColumnField Assisted");
        subTerm3.addChildTerm("多场辅助", "Multi-ColumnField Assisted");
        subTerm3.addChildTerm("OOP圆柱状", "Magnetization out of plane");
        subTerm3.addChildTerm("圆柱状", "Cylinder type");
        subTerm3.addChildTerm("复合自由层", "Composited Free layer");
        subTerm3.addChildTerm("单自由层", "Single free layer");
        subTerm3.addChildTerm("热辅助", "Heat assisted");
        subTerm3.addChildTerm("磁场辅助", "Magnetic field assisted");
        subTerm3.addChildTerm("新型氧化物", "new-type Oxide");

        subTerm4.addChildTerm("面内", "in-plane");
        subTerm4.addChildTerm("面外", "Out-of-plane");
        subTerm4.addChildTerm("磁场偏置型", "Magnetic field biased SOT-MRAM");
        subTerm4.addChildTerm("无磁场偏置型", "ColumnField-free SOT-MRAM");
        subTerm4.addChildTerm("磁性绝缘体", "Magnetic Insulator");
        subTerm4.addChildTerm("微波辅助", "Microwave-assisted");
        subTerm4.addChildTerm("电场辅助", "Electric field assisted");
        subTerm4.addChildTerm("热辅助", "Heat assisted");
        subTerm4.addChildTerm("3端口", "Three terminal");
        subTerm4.addChildTerm("2端口", "Two terminal");
        subTerm4.addChildTerm("金属型", "Metal type");
        subTerm4.addChildTerm("拓扑绝缘体型", "Topologic Insulator Type");

        subTerm5.addChildTerm("电流写入", "Current writing");
        subTerm5.addChildTerm("奈尔畴壁型", "Neel wall type");
        subTerm5.addChildTerm("布洛赫畴壁型", "Bloch wall type");
        subTerm5.addChildTerm("氧化镁", "MgO");
        subTerm5.addChildTerm("三氧化二铝", "Al2O3");
        subTerm5.addChildTerm("铝酸镁", "MgAl2O4");
        subTerm5.addChildTerm("氧化钛", "TiO");
        subTerm5.addChildTerm("IP", "In plane magnetization");
        subTerm5.addChildTerm("垂直磁化", "Perpendicular magnetization");
        subTerm5.addChildTerm("单自由层", "单自由层");
        subTerm5.addChildTerm("复合自由层", "Composite free layer");

        subTerm6.addChildTerm("三维赛道", "3D racetrack");
        subTerm6.addChildTerm("面内赛道", "In plane Racetrack");
        subTerm6.addChildTerm("电流奥斯特场写入", "Oersted ColumnField");
        subTerm6.addChildTerm("STT写入", "Spin transfer torque");
        subTerm6.addChildTerm("临近单元杂散场", "Fringing fields from proximal element");
        subTerm6.addChildTerm("奈尔畴壁型", "Neel wall type");
        subTerm6.addChildTerm("布洛赫畴壁型", "Bloch wall type");
        subTerm6.addChildTerm("磁阻传感器读取", "Magnetoresistance sensor");
        subTerm6.addChildTerm("磁性纳米线", "Magnetic nanowire");
        subTerm6.addChildTerm("小尺寸", "Small size");
        subTerm6.addChildTerm("IP", "In plane magnetization");
        subTerm6.addChildTerm("垂直磁化", "Perpendicular magnetization");
        subTerm6.addChildTerm("涡旋态磁畴壁", "Votex wall");

        subTerm7.addChildTerm("电流驱动", "Current driven");
        subTerm7.addChildTerm("热驱动", "Heat driven");
        subTerm7.addChildTerm("电场驱动", "Electric field driven");
        subTerm7.addChildTerm("磁场驱动", "Magnetic field driven");
        subTerm7.addChildTerm("拓扑霍尔效应", "Topological Hall Effect");
        subTerm7.addChildTerm("磁性隧道结", "Magnetic Tunnel Junction MTJ");
        subTerm7.addChildTerm("霍尔传感器", "Hall Sensor");
        subTerm7.addChildTerm("奈尔壁", "Neel Type");
        subTerm7.addChildTerm("布洛赫壁", "Bloch Type");
        subTerm7.addChildTerm("纳米管", "Nanotube");
        subTerm7.addChildTerm("纳米线", "Nanowire");
        subTerm7.addChildTerm("异质结薄膜", "Heterojunction film");

        subTerm8.addChildTerm("场控磁各向异性", "Voltage control magnetic anisotropy");
        subTerm8.addChildTerm("应力辅助", "Strain assist");
        subTerm8.addChildTerm("电极化相互作用", "Interaction of electrical polarization");
        subTerm8.addChildTerm("磁电耦合", "Magnetoelectric coupling");
        subTerm8.addChildTerm("衬底层", "Substrate");
        subTerm8.addChildTerm("碳化硅", "SiC");
        subTerm8.addChildTerm("硅", "Si");
        subTerm8.addChildTerm("玻璃衬底", "glass substrate");
        subTerm8.addChildTerm("单晶氧化物衬底", "single crystal oxide");
        subTerm8.addChildTerm("有机柔性衬底", "organic flexible substrate");
        subTerm8.addChildTerm("铁电或多铁性衬底", "ferroelectric or multiferroic");
        subTerm8.addChildTerm("金属磁性层", "metallic ferromagnetic layer");
        subTerm8.addChildTerm("稀磁半导体磁性层", "Diluted magnetic semiconductors");
        subTerm8.addChildTerm("半金属磁性层", "Half metallic ferromagnetic layer");
        subTerm8.addChildTerm("介电层", "Dielectric");
        subTerm8.addChildTerm("铁电层", "ferroelectric function layer");
        subTerm8.addChildTerm("功能层", "");
        subTerm8.addChildTerm("PLD", "Pulse laser deposition");
        subTerm8.addChildTerm("ALD", "Atomic layer deposition");
        subTerm8.addChildTerm("MBE", "Molecular beam epitaxy");
        subTerm8.addChildTerm("磁控", "Magnetron sputtering");

        term.addChildTerm(subTerm1);
        term.addChildTerm(subTerm2);
        term.addChildTerm(subTerm3);
        term.addChildTerm(subTerm4);
        term.addChildTerm(subTerm5);
        term.addChildTerm(subTerm6);
        term.addChildTerm(subTerm7);
        term.addChildTerm(subTerm8);

        return term;

    }

}
